home *** CD-ROM | disk | FTP | other *** search
- var gYBLoginWindow = null;
-
- var YBidManager = {
-
- _syncService : Components.classes["@mozilla.org/ybookmarks-sync-service;1"].
- getService(Components.interfaces.nsIYBookmarkSyncService),
- _windowMediator : Components.classes["@mozilla.org/appshell/window-mediator;1"].
- getService(Components.interfaces.nsIWindowMediator),
- _localStoreService : Components.classes["@mozilla.org/ybookmarks-store-service;1"].
- getService(Components.interfaces.nsIYBookmarksStoreService),
- _socialStoreService : Components.classes["@yahoo.com/socialstore/delicious;1"].
- getService(Components.interfaces.nsISocialStore),
- _prefs : Components.classes["@mozilla.org/preferences-service;1"].
- getService(Components.interfaces.nsIPrefBranch),
-
- setLastUsername: function( username ) {
- yDebug.print( "Last user name set to " + username );
-
- this._prefs.setCharPref(
- "extensions.ybookmarks@yahoo.login.last", username);
- },
-
- observe: function( subject, topic, data ) {
- try {
- if (topic == "ybookmark.userChanged" && data == "silentlogout") {
- this._silentLogout();
- return;
- }
- else if ( data == "loggedin" ) {
- //Find re-login / User change.
- var userChanged = false;
- var del = Components.classes["@yahoo.com/socialstore/delicious;1"]
- .getService( Components.interfaces.nsISocialStore );
- var username = del.getUserName();
- var lastLogin = null;
- try {
- lastLogin = this._prefs.getCharPref("extensions.ybookmarks@yahoo.login.last");
- } catch (e) {}
- userChanged = (username != lastLogin);
- if (userChanged) {
-
- this._loginChanged();
- } else {
- this._loggedIn();
- }
- } else if ( data == "loggedout") {
- this._loggedOut();
- return;
- } else if (data == "cookie_expired") {
- this._cookieExpired();
- return;
- }
- } catch (e) {
- yDebug.print("idManager.js::observe()=>Exception: "+e,YB_LOG_MESSAGE);
- }
- },
-
- _loggedIn: function() {
- yDebug.print("idManager.js::YBidManager::_loggedIn",YB_LOG_MESSAGE);
- var recentWindow =
- this._windowMediator.getMostRecentWindow("navigator:browser");
- var del = Components.classes["@yahoo.com/socialstore/delicious;1"]
- .getService( Components.interfaces.nsISocialStore );
- var username = del.getUserName();
-
- this.setLastUsername(username);
-
- ybookmarksMain.setLoggedInState(username);
-
- if (this._isEngineInstalled() ) {
- if (recentWindow == window) {
- setTimeout(function(syncService, socialStoreService) {
- syncService.allowSync();
- syncService.sync(true);
- socialStoreService.allowImportPolling();
-
- }, 2000, this._syncService, this._socialStoreService);
- }
- }
- },
-
- _loginChanged: function() {
- yDebug.print("idManager.js::YBidManager::_loginChanged",YB_LOG_MESSAGE);
- var recentWindow =
- this._windowMediator.getMostRecentWindow("navigator:browser");
- var del = Components.classes["@yahoo.com/socialstore/delicious;1"]
- .getService( Components.interfaces.nsISocialStore );
- var username = del.getUserName();
- if (username) {
- this.setLastUsername(username);
- ybookmarksMain.setLoggedInState(username);
- }
- else {
- ybookmarksMain.setLoggedOutState();
- }
-
- if (this._isEngineInstalled() ) {
- if (recentWindow == window) {
- this._cancelSync();
- if (username) {
- this._removeUsersBookmarksStore();
- setTimeout(function(syncService, socialStoreService) {
- syncService.allowSync();
- syncService.sync(true);
- socialStoreService.allowImportPolling();
- }, 2000, this._syncService, this._socialStoreService);
- }
- }
- }
- },
-
-
- _silentLogout: function( ) {
- yDebug.print("idManager.js::YBidManager::_silentLogout",YB_LOG_MESSAGE);
-
- ybookmarksMain.setLoggedOutState();
-
- if (this._isEngineInstalled() ) {
- this._cancelSync();
- this._socialStoreService.disallowImportPolling();
- //Keep local copy of bookmarks, We ask user via the above dialog to keep/remove
- YBidManager.keepLocalContent();
- this._localStoreService.setLastUpdateTime("-1");
- this._localStoreService.flush(true);
- }
- },
-
- _loggedOut: function( ) {
- yDebug.print("idManager.js::YBidManager::_loggedOut",YB_LOG_MESSAGE);
- var recentWindow =
- this._windowMediator.getMostRecentWindow("navigator:browser");
-
- ybookmarksMain.setLoggedOutState();
-
- if(ybookmarksUtils.getExtensionMode() == YB_EXTENSION_MODE_CLASSIC) {
- //No need to show loggedout dialog in classic mode.
- return;
- }
-
- if (this._isEngineInstalled() ) {
- if (recentWindow == window) {
- var rv = { remove : false };
-
- this._cancelSync();
- this._socialStoreService.disallowImportPolling();
- yDebug.print("idManager.js::YBidManager::_loggedOut=>Opening keep local content dialog.",YB_LOG_MESSAGE);
- window.openDialog( "chrome://ybookmarks/content/loggedOut.xul",
- "LoggedOut",
- "chrome,dialog,centerscreen,modal,resizable=no", rv);
- //Keep local copy of bookmarks, We ask user via the above dialog to keep/remove
- YBidManager.keepLocalContent();
- if (rv.remove) {
- this._removeUsersBookmarksStore();
- }
- else {
- //force a partial sync if the same user login again
- this._localStoreService.setLastUpdateTime("-1");
- this._localStoreService.flush(true);
- }
- }
- }
- },
-
- _cookieExpired: function() {
- var recentWindow =
- this._windowMediator.getMostRecentWindow("navigator:browser");
- ybookmarksMain.setLoggedOutState();
- if (this._isEngineInstalled() ) {
- if (recentWindow == window) {
- this._cancelSync();
- this._socialStoreService.disallowImportPolling();
- YBidManager.keepLocalContent();
- //force a partial sync if the same user login again
- this._localStoreService.setLastUpdateTime("-1");
- this._localStoreService.flush(true);
- }
- }
- },
-
- _isEngineInstalled : function() {
- var installed = false;
- var strings = document.getElementById("ybookmarks-strings");
- var newVersionNum = strings.getString("extensions.ybookmarks.versionNum");
- yDebug.print("idManager.js::YBidManager::_isEngineInstalled()=>newVersionNum= "+newVersionNum,
- YB_LOG_MESSAGE);
-
- try {
- var prefs = Components.classes["@mozilla.org/preferences-service;1"]
- .getService(Components.interfaces.nsIPrefBranch);
- var oldVersionNum = prefs.getCharPref("extensions.ybookmarks@yahoo.version.number");
- yDebug.print("idManager.js::YBidManager::_isEngineInstalled()=>oldVersionNum= "+oldVersionNum,
- YB_LOG_MESSAGE);
-
- }catch (e){
- yDebug.print("idManager.js::YBidManager::_isEngineInstalled()=>Engine not installed",
- YB_LOG_MESSAGE);
- }
- if(newVersionNum == oldVersionNum){
- installed = true;
- yDebug.print("idManager.js::YBidManager::_isEngineInstalled()=>Engine installed",
- YB_LOG_MESSAGE);
- }
- return installed;
- },
-
- /**
- * Cancel the sync
- *
- */
- _cancelSync : function() {
-
- this._syncService.cancelSync();
- //this._localStoreService.removeAllTransactions(10);
- },
-
- /**
- * Remove bookmarks,bundles and transactions list.
- *
- */
- _removeUsersBookmarksStore : function() {
- this._localStoreService.deleteAllBookmarks(true);
- this._localStoreService.clearBundles();
- this._localStoreService.removeAllTransactions(10);
- ybToolbar.refreshCurrentView();
- },
-
- /* logoutWindowShown: function() {
- var bundle, serviceName, str, elt, i;
-
- bundle = document.getElementById( "strbndl_idManager");
-
- str = bundle.getFormattedString( "extensions.ybookmarks.loggedOut.dialog.title", [ serviceName ] );
- document.title = str;
- },
- */
- onLogoutWindowAccept: function(event) {
- var radio = document.getElementById("ybLoggedOut-radio");
- var keepRadio = document.getElementById("ybLoggedOut-radio-keep");
- if (radio.selectedItem == keepRadio) {
- YBidManager.keepLocalContent();
- } else {
- YBidManager.removeLocalContent();
- }
- return true;
- },
-
-
- keepLocalContent: function() {
- try {
- window.arguments[0].remove = false;
- } catch(e) { //do nothing
- }
- //window.close();
- },
-
- removeLocalContent: function() {
- try {
- window.arguments[0].remove = true;
- } catch(e) {
- // do nothing
- }
- //window.close();
- },
-
- isUserLoggedIn: function() {
- try {
- var silentMode = Components.classes["@mozilla.org/preferences-service;1"]
- .getService(Components.interfaces.nsIPrefBranch)
- .getBoolPref("extensions.ybookmarks@yahoo.delicious.silentlogout");
- if(silentMode) {
- return false;
- }
- } catch(e) {}
- return (this._socialStoreService.getUserName() ? true : false);
- },
-
- promptUserLogin: function() {
- window.ybLoginWindowFlag = "";
- window.openDialog( "chrome://ybookmarks/content/reqUserCred.xul",
- "ReqUserCred",
- "chrome,dialog,centerscreen,modal,resizable=no" );
- },
-
- acctSetupDlgShown: function() {
- var bundle = document.getElementById( "strbndl_idManager");
-
- var serviceName = deliciousService.getServiceName();
- var str = bundle.getFormattedString( "extensions.ybookmarks.reqUserCred.message", [ serviceName ] );
- ( document.getElementById( "desc_mainText" ) ).appendChild( document.createTextNode( str ) );
- str = bundle.getFormattedString( "extensions.ybookmarks.reqUserCred.dialog.title",
- [ serviceName ] );
- document.title = str;
- },
-
- cancel: function() {
- window.close();
- },
-
- showAcctSetup: function() {
- window.close();
- ybookmarksUtils.openPreferences( "yb_account" );
- },
-
- showLoginPage: function() {
- window.opener.ybLoginWindowFlag = "display";
- window.close();
- },
-
- switchToClassicModeWarning: function(event) {
- _userSelection = "cancel";
- window.openDialog( "chrome://ybookmarks/content/switchtoClassic.xul",
- "Switch To Classic",
- "chrome,dialog,centerscreen,modal,resizable=no");
-
- ////Disable the switch mode buttton.
- var pref = Components.classes["@mozilla.org/preferences-service;1"].
- getService(Components.interfaces.nsIPrefBranch);
- try {
- var modeChange = pref.getCharPref("extensions.ybookmarks@yahoo.engine.set.mode");
- if(modeChange == YB_EXTENSION_MODE_CLASSIC) {
- var switchButton = document.getElementById("btn_classic_mode");
- switchButton.disabled = true;
- }
- } catch(e){}
-
- //Restart
- if(_userSelection == "restart") {
- _userSelection = "cancel";
- ybookmarksUtils._quit(true);
- }
- },
-
- modeChangeToClassic : function() {
- //set the mode pref value.
- var pref = Components.classes["@mozilla.org/preferences-service;1"].
- getService(Components.interfaces.nsIPrefBranch);
- pref.setCharPref("extensions.ybookmarks@yahoo.engine.set.mode", YB_EXTENSION_MODE_CLASSIC);
- //Keep/Remove bookmarks
- var radio = document.getElementById("ybLoggedOut-radio");
- var keepRadio = document.getElementById("ybLoggedOut-radio-keep");
- if (radio.selectedItem == keepRadio) {
- } else {
- YBidManager._cancelSync();
- YBidManager._socialStoreService.disallowImportPolling();
- YBidManager._removeUsersBookmarksStore();
- }
- var restartCheck = document.getElementById("ybRestartNow");
- if(restartCheck.checked) {
- //Restart hack
- window.opener._userSelection = "restart";
- //ybookmarksUtils._quit(true);
- }
- return true;
- },
-
- switchToStandardMode: function() {
- var params = {out:null};
- window.openDialog("chrome://ybookmarks/content/switchToRegMode.xul", "", "chrome,dialog,centerscreen,modal,resizable=no", params);
- if(params.out) {
- //set the mode pref value and restart.
- var pref = Components.classes["@mozilla.org/preferences-service;1"].
- getService(Components.interfaces.nsIPrefBranch);
- pref.setCharPref("extensions.ybookmarks@yahoo.engine.set.mode", YB_EXTENSION_MODE_STANDARD);
- ybookmarksUtils.restartBrowser();
- }
- return true;
- }
-
- };
-
-